/**
    @project {
        "templateId": "org.helgoboss.custom",
        "version": "0.1-SNAPSHOT",
        "dependencies": [
            "org.scala-lang:scala-library:2.9.0-1",
            "org.helgoboss:one-filer-ref-impl:0.1-SNAPSHOT",
            "org.helgoboss:osgi-additions:0.1-SNAPSHOT",
            "org.helgoboss:one-filer-template-manager:0.1-SNAPSHOT"
        ]
    }
*/

package org.helgoboss.one_filer_ref_impl_activator

import org.helgoboss.osgi_additions._
import org.helgoboss.one_filer_template_manager.OneFilerTemplateManager
import org.helgoboss.one_filer_template.OneFilerTemplate
import org.helgoboss.one_filer_ref_impl.OneFilerRefImpl
import org.helgoboss.one_filer.OneFiler

class Activator extends OsgiContext with OsgiServiceWatcher with OsgiProvider {
    whenBundleActive {
        val m = new OneFilerTemplateManager
        watchServices[OneFilerTemplate] {
            case AddingService(t, _) => m.registerTemplate(t)
            case RemovedService(t, _) => m.unregisterTemplate(t)
        }
        new OneFilerRefImpl(lookupTemplate = m.findTemplate _).providesService[OneFiler]
    }
}
